package edu.gatech.oad.OTConfig;
/**
 * This is the StoreController Class
 * This class handles operations that take place in the store
 * @author Chris Adams
 * @version 1.0 10/20/2011
 */

public class StoreController {

	private WagonInventory wagonInv;
	private StoreInventory storeInv;

	/**
	 * Constructor for the StoreController class. Instantiates an inventory controller
	 */
	public StoreController(InventoryController invControl, int quantitySeed){
		wagonInv = invControl.getWagonInventory();
		storeInv = new StoreInventory(quantitySeed);
	}

	/**
	 * Uses the inventory controller to buy an item
	 * 
	 * @param item Item type to buy
	 * @param quantity Quantity of items to buy
	 */
	public void buyItem(Item item, int quantity){
		item.setQuantity(-quantity);
		//System.out.println("Quantity to be subtracted from the store: " + -quantity);
		storeInv.add(item);
		item.setQuantity(quantity);
		//System.out.println("Quantity to be added to the wagon: " + quantity);
		wagonInv.add(item);
	}

	/**
	 * Uses the inventory controller to sell an item
	 * 
	 * @param item Item type to sell
	 * @param quantity Quantity of items to sell
	 */
	public void sellItem(Item item, int quantity){
		item.setQuantity(-quantity);
		wagonInv.add(item);
		item.setQuantity(quantity);
		storeInv.add(item);
	}

	/**
	 * Re-populates store 
	 */
	public void repopulateStore(){
		/*Set quantities*/
		storeInv.get(Inventory.OXEN).setQuantity(10);
		storeInv.get(Inventory.FOOD).setQuantity(100);
		storeInv.get(Inventory.CLOTHING).setQuantity(10);
		storeInv.get(Inventory.AMMUNITION).setQuantity(50);
		storeInv.get(Inventory.WHEELS).setQuantity(10);
		storeInv.get(Inventory.AXLE).setQuantity(10);
		storeInv.get(Inventory.TONGUE).setQuantity(10);
	}
	/**
	 * Re-prices items based on a multiplier passed.
	 * @param multiplier
	 */
	public void reprice(float multiplier){
		for (Item item:storeInv){
			item.setPrice(Math.round((item.getBASE_PRICE()*multiplier)));
		}
		for (Item item:wagonInv){
			item.setPrice(Math.round((item.getBASE_PRICE()*multiplier)));
		}
		
	}

	/**
	 * Gets a list of the current items in the wagon
	 * @return List of items in the wagon
	 */
	public WagonInventory getWagonInventory(){
		return wagonInv;
	}

	/**
	 * Gets a list of the current items in the store
	 * @return List of items in the store
	 */
	public StoreInventory getStoreInventory(){
		return storeInv;
	}
}
